#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    printf("I am a process pid: %d ppid: %d\n", getpid(), getppid());

    pid_t ret = fork();
    if (ret == 0)
    {
        for (int i = 0; i < 5; ++i)
        {
            printf("我是子进程 pid: %d ppid: %d\n", getpid(), getppid());
            sleep(1);
        }
        printf("------------------------------------------\n");
        printf("子进程退出了\n");
    }
    else if (ret > 0)
    {
        while (1)
        {
            printf("我是父进程 pid: %d ppid: %d\n", getpid(), getppid());
            sleep(1);
        }
    }
    else
        printf("fork error\n");

    return 0;
}
